package manage.action;

import m.common.action.ActionMeta;
import m.common.action.RequestMeta;
import m.common.model.util.QueryPage;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import manage.model.IconInfo;
import manage.service.IconInfoService;

import java.io.File;
import java.sql.SQLException;
import java.util.Map;

@ActionMeta(name="manage/iconInfo")
public class IconInfoAction extends ManageAction {

	/**
	 * 上传文件
	 * 
	 */
	@RequestMeta(params= {"business"})
	public JSONMessage upload(String business) throws Exception {
		verifyAdminOperPower("manage_system_power");
		Map<String,File> map=super.getFileMap();
		IconInfo model=null;
		for(String key : map.keySet()){
			String name=map.get(key).getName();
			model=new IconInfo();
			model.setBusiness(business);
			model.setName(name.substring(name.indexOf("_uploadFile_")+12));
			getService(IconInfoService.class).saveIcon(model,map.get(key));
			break;
		}
		return new JSONMessage(0)
				.push("model", model);
	}

	/**
	 * 获取icon列表
	 * 
	 */
	@RequestMeta(params= {"page","name","business"})
	public JSONMessage iconList(QueryPage page,String name,String business) throws MException, SQLException {
		//verifyAdminOperPower("manage_system_power");
		return new JSONMessage(0)
				.push("list", getService(IconInfoService.class).getIconList(page,name,business));
	}

}
